<?php

/**
 * Controller_teacher
 教师档案
 */

class Controller_teacher extends MyApp {


	public function __construct()
	{
		parent::__construct();

		$this->model->excel    	= YOU::loadModel('excel');
		$this->model->semester 	= YOU::loadModel('semester');
		$this->model->record 	= YOU::loadModel('record');
		$this->model->user   	= YOU::loadModel('user');
		$this->model->staff   	= YOU::loadModel('staff');
	}

	/** 首页 **/
	public function actionIndex()
	{

	}

	/** 教师档案列表 **/
	public function actionList ()
	{

		//按条件搜索
		$where = "  ";

		//获取到页面传过来的要搜索的条件
		$staff_position   = (int)$this->get->staff_position;
		$staff_education  = (int)$this->get->staff_education;
		$staff_name       = $this->get->staff_name;

		if (!empty($staff_position)) {
			$where .= " AND staff_position='{$staff_position}' ";
			$this->tpl->assign("staff_positon", $staff_position);
		}
		if (!empty($staff_education)) {
			$where .= " AND staff_education='{$staff_education}' ";
			$this->tpl->assign("staff_education", $staff_education);
		}
		if (!empty($staff_name)) {
			$where .= " AND staff_name LIKE '{$staff_name}%' ";
			$this->tpl->assign("staff_name", $staff_name);
		}

		// 分页
		YOU::loadLib('page', "", '0');
		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE staff_external= '0' {$where} ");
		$count = $tmp['count'];
		$page_total = ceil($count/PAGE_LIMIT);

		// 当前页
		$p = intval($_GET['p']);
		if ($p == 0){
			$p  = 1;
		}
		if ($p > 1){
			$start = PAGE_LIMIT * ($p-1);
		}else{
			$start = 0;
		}

		// 非全部数据输出状态下才分页
		if(empty($this->get->output)){
			$limit = " LIMIT {$start}, ".PAGE_LIMIT;
		}else{
			$limit = "";
		}

		$staff_lists = $this->db->fetchAll("SELECT * FROM `tbl_staff` WHERE staff_external= '0' {$where} ORDER BY staff_id DESC {$limit} ");
		foreach ($staff_lists as $key => $value){

			$staff_lists[$key]['staff_sex']       = $this->sex_ini[$value['staff_sex']];
			$staff_lists[$key]['staff_position']  = $this->position_ini[$value['staff_position']];
			$staff_lists[$key]['staff_education'] = $this->education_ini[$value['staff_education']];
			$staff_lists[$key]['staff_sign']      = $this->sign_ini[$value['staff_sign']];
		}

		$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
		$page->next_page   = '下一页>';
		$page->pre_page    = '<上一页';
		$page->style_path  = "static/page_style";

		//按条件搜索结果  把职位 部门全部罗列到页面
		$department_lists = $this->db->fetchAll("SELECT `department_id`,`department_name` FROM `tbl_department`");
		$position_lists   = $this->db->fetchAll("SELECT `position_id`,`position_name` FROM `tbl_position`");

		//教师档案项目用反序列化取出
		$record_lists = $this->model->record->getInfo("teacher_list");

		$staffnew_lists = array();
		// 取所有员工
		foreach ($staff_lists as $key => $value){
			$staffnew_lists[$key]['staff_id'] = $value['staff_id'];
			// 反序列化的数组
			foreach ($record_lists as $k => $v){
				$staffnew_lists[$key][$v['name']] = $value[$v['name']];
				//性别显示
				if ($v['name'] == "staff_sex") {
					$staffnew_lists[$key][$v['name']] =  $this->sex_ini[$value[$v['name']]];
				}
				//职称显示
				if ($v['name'] == "staff_position") {
					$staffnew_lists[$key][$v['name']] =  $this->position_ini[$value[$v['name']]];
				}
				//在职标记显示
				if ($v['name'] == "staff_sign") {
					$staffnew_lists[$key][$v['name']] =  $this->sign_ini[$value[$v['name']]];
				}
			}
		};

		$this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("staff_lists", $staff_lists);
		$this->tpl->assign("staffnew_lists", $staffnew_lists);
		$this->tpl->assign("department_lists", $department_lists);

		$this->tpl->assign("position_lists", $position_lists);
		$this->tpl->assign("record_lists", $record_lists);
		$this->tpl->display("teacher/teacher.list.tpl.php");
	}

	// 导出excel
	public function actionoutData() {
		$staff_lists = $this->db->fetchAll("SELECT * FROM `tbl_staff`WHERE staff_external= '0'  ORDER BY staff_id ");
		//var_dump($staff_lists);exit;
		$rule = $this->model->record->getInfo('teacher_list');
		$col = array();
		foreach($rule as $k => $v){
			$col[] = $v['title'];
		}
		//var_dump($col);exit;
		$info = array();

		foreach ($staff_lists as $key => $value) {
			$i = 0;
			foreach ($rule as $k => $v){

				switch ($v['name']){
					case  'staff_card':
						$info[$i] = ' '.$value[$v['name']];
						break;
					case  'staff_graduate_time':
						$info[$i] = ' '.$value[$v['name']];
						break;
					case  'staff_tel':
						$info[$i] = ' '.$value[$v['name']];
						break;
					case  'staff_fix':
						$info[$i] = ' '.$value[$v['name']];
						break;
						//                    case  'staff_party_date':
						//                        $info[$i] = ' '.$value[$v['name']];
						//                        break;
						//                    case  'staff_ctime':
						//                        $info[$i] = ' '.$value[$v['name']];
						//                        break;
					case  'end_time':
						$info[$i] = ' '.$value[$v['name']];
						break;
					case  'start_time':
						$info[$i] = ' '.$value[$v['name']];
						break;
					case  'staff_number':
						$info[$i] = ' '.$value[$v['name']];
						break;
					case  'staff_sex':
						$info[$i] = $this->sex_ini[$value[$v['name']]];
						break;
					case  'staff_education':
						$info[$i] = $this->education_ini[$value[$v['name']]];
						break;
					case  'staff_position':
						$info[$i] = $this->position_ini[$value[$v['name']]];//职称
						break;
						//                    case  'staff_position':
						//                        $info[$i] = $this->position_type[$value[$v['name']]];//在职标记
					case  'staff_sign':
						$info[$i] = $this->sign_ini[$value[$v['name']]];
						break;
					case  'staff_party':
						$info[$i] = $this->party_ini[$value[$v['name']]];
						break;
					case  'staff_assess':
						$info[$i] = $this->assess_ini[$value[$v['name']]];
						break;
						//                    case  'staff_nature':
						//                        $info[$i] = $this->staff_nature_ini[$value[$v['name']]];
						//                        break;
					default:
						$info[$i] = $value[$v['name']];
				}
				$i++;

			}
			$data_lists[$key] = $info;

		}
		// var_dump($data_lists);exit;
		$this->model->excel->excel_ini['teachercount']['title'] = "教师统计表";
		$this->model->excel->excel_ini['teachercount']['col'] = $col;
		$this->model->excel->outData("teachercount", $data_lists);
	}

	/** 批量导入教师信息 **/
	public function actionIn()
	{
		//echo date('Y-m-d',strtotime('1994-01-03'));exit;

		if($_POST){


			$check = $this->post->check;
			//var_dump($check);exit;
			$data = $this->model->excel->in('teachercount');
			//var_dump($data);exit;

			if($check!=='on'){
				foreach ($data as $k => $v){
					$staff_card = $v['7'];
					$row = $this->db->fetchRow("SELECT staff_card FROM `tbl_staff` WHERE staff_card='{$staff_card}' ");
					if (!empty($row)) {
						$mes = "教师信息已存在，身份证号码为： ";
						$check = 2;
						$this->tpl->assign("mes", $mes);
						$this->tpl->assign("staff_card", $staff_card);
						$this->tpl->assign("check", $check);
						$this->tpl->display("teacher/teacher.in.tpl.php");
						exit;
					}

				}
			}



			if(empty($data)){
				Helper_Client::alert("请上传文件");
			}
			foreach ($data as $key => $value){

				//echo $value[15];echo'    '. $value[16];exit;
				switch ($value[12]){
					case '党员':
						$value[12] = 1;
						break;
					case '非党员':
						$value[12] = 0;
						break;
					case '预备党员':
						$value[12] = 2;
						break;
					default:
						$value[12] = 0;
				}

				switch ($value[40]){
					case '专科以下':
						$value[40] = 1;
						break;
					case '专科':
						$value[40] = 2;
						break;
					case '本科':
						$value[40] = 3;
						break;
					case '研究生':
						$value[40] = 4;
						break;
					case '研究生以上':
						$value[40] = 5;
						break;
				}
				switch ($value[39]){
					case '未定级';
					$value[39] = 1;
					break;
					case '一级';
					$value[39] = 2;
					break;
					case '二级';
					$value[39] = 3;
					break;
					case '三级';
					$value[39] = 4;
					break;
					case '高级';
					$value[39] = 5;
					break;
					case '正高级';
					$value[39] = 6;
					break;
				}
				// echo $value[37];exit;
				$info = array(
				"staff_name" => $value[1],
				"staff_usedname" => $value[2],
				"staff_sex" => $value[3]=='男'?1:0,
				"staff_number" => ''.$value[4],
				"staff_area" => $value[5],
				"staff_idtype" => $value[6],//证件类型
				"staff_card" => ''.$value[7],
				"staff_birth" => $value[8],//date('Y-m-d',strtotime($value[8])),
				"staff_home" => $value[9],
				"staff_city" => $value[10],
				"staff_nation" => $value[11],
				"staff_party" => $value[12],
				"staff_marry" => $value[13],
				"staff_health" => $value[14],
				"start_time" => $value[15],//date('Y-m',strtotime($value[15])),
				"end_time" => $value[16],//date('Y-m',strtotime($value[16])),
				"staff_orignal" => $value[17],
				"staff_classes" => $value[18],//leibie
				"staff_nature" => $value[19],//zaibian
				"staff_style" => $value[20],
				"staff_signed" => $value[21],
				"staff_normal" => $value[22],
				"staff_skill" => $value[23],
				"staff_certificate" => $value[24],
				"staff_info" => $value[25],
				"staff_free" => $value[26],
				"staff_basic" => $value[27],
				"staff_basic_start" => $value[28],
				"staff_basic_end" => $value[29],
				"staff_super" => $value[30],
				"staff_bone" => $value[31],
				"staff_mental" => $value[32],
				"staff_zhuang" => $value[33],//zhuangtai
				"staff_ctime" => date('Y-m-d',strtotime($value[34])),//diaodong
				"staff_party_date" => $value[35],//date('Y-m-d',strtotime($value[35]))
				"staff_addr" => $value[36],
				"staff_fix" => ' '.''.$value[37],
				"staff_tel" => ''.$value[38],
				"staff_position" => $value[39],//zhicheng
				"staff_education" => $value[40],
				"staff_school" => $value[41],
				"staff_graduate_time" => date('Y-m-d',strtotime($value[42])),
				"staff_remark" => $value[43],
				//"17" "staff_file" => $value[],
				);
				//var_dump($info);exit;
				$staff_card = $value['7'];
				$row = $this->db->fetchRow("SELECT staff_card FROM `tbl_staff` WHERE staff_card='{$staff_card}' ");
				if (!empty($row)) {
					$this->db->do_update("tbl_staff", $info, "staff_card='{$staff_card}'" );
				}else{
					$this->model->user->add("staff", $info);
				}

			}
			//echo 123;exit;
			// 跳转
			Helper_Client::location("添加成功", "index.php?a=teacher.list");


		}

		$this->tpl->display("teacher/teacher.in.tpl.php");
	}

	/** 教师档案添加 **/
	public function actionAdd()
	{
		// 职称
		$position	=	$this->position_ini;
		// 学历
		$education  =   $this->education_ini;
		// 职工类型
		//$nature     =   $this->staff_nature_ini;
		// 党员显示
		$party      =	$this->party_ini;
		// 教师
		$staff_nature = 1;
		if ($_POST){
			//var_dump($this->post->start_time);exit;
			$staff_name      = $this->post->staff_name;
			$staff_number    = $this->post->staff_number;
			$staff_sex       = $this->post->staff_sex;
			$staff_position  = $this->post->staff_position;
			$staff_education = $this->post->staff_education;
			$staff_birth     = $this->post->staff_birth;
			$staff_card      = $this->post->staff_card;
			$staff_entry     = $this->post->staff_entry;
			$staff_img       = $this->post->staff_img;
			$staff_file      = $this->post->staff_file;
			$start_time      = $this->post->start_time;
			$end_time        = $this->post->end_time;
			$staff_tel       = $this->post->staff_tel;
			//$staff_nature    = $this->post->staff_nature;
			$staff_party     = $this->post->staff_party;

			//查询数据库staff表中的身份证号码是否唯一
			$row = $this->db->fetchRow("SELECT staff_id FROM `tbl_staff` WHERE staff_card='{$staff_card}'");
			//查询数据库staff表中的身份证号码是否唯一
			$rows = $this->db->fetchRow("SELECT staff_id FROM `tbl_staff` WHERE staff_number='{$staff_number}' ");
			if (!empty($row)) {
				Helper_Client::alert("该身份证号码已经存在");
			}elseif(!empty($rows)){
				Helper_Client::alert("该编号已经存在");
			}else{

				// 写入数据库
				$info = array(
				"staff_name"       => $staff_name,
				"staff_number"     => $staff_number,
				"staff_sex"        => $staff_sex,
				"staff_position"   => $staff_position,
				"staff_education"  => $staff_education,
				"staff_party"      => $staff_party,
				"staff_birth"      => $staff_birth,
				"staff_card"       => $staff_card,
				"staff_entry"      => $staff_entry,
				"staff_img"        => $staff_img,
				"staff_file"       => $staff_file,
				"start_time"       => $start_time,
				"end_time"         => $end_time,
				"staff_tel"        => $staff_tel,
				"staff_nature"     => $staff_nature,
				"staff_external"   => 0,
				);

				/*
				$this->db->do_insert("tbl_staff", $info);
				$staff_id  	= $this->db->insert_id();

				// 插入年度考核表
				// 写入数据库
				$info = array(

				"staff_id"       	=> $staff_id,
				"status"           	=> 1,
				"create_time"      	=> date("Y-m-d H:i:s"),
				"update_time"      	=> "0000-00-00 00:00:00",
				);

				$this->db->do_insert("tbl_assess", $info);
				*/
				$this->model->user->add("staff", $info);
				// 插入年度考核表

			}
			// 跳转
			Helper_Client::location("添加成功", "index.php?a=teacher.list");
		}
		$this->tpl->assign("position", $position);
		$this->tpl->assign("education", $education);
		$this->tpl->assign("nature", $nature);
		$this->tpl->assign("party", $party);

		$this->tpl->assign("staff_nature", $staff_nature);

		$this->tpl->display("teacher/teacher.add.tpl.php");
	}

	/** 教师档案修改 **/
	public function actionUpdate()
	{
		$staff_id   = (int)$this->get->staff_id;
		$staff_data = $this->db->fetchRow("SELECT * FROM `tbl_staff` WHERE staff_id='{$staff_id}'");
		if (empty($staff_data)){
			Helper_Client::alert("人员不存在");
		}
		// 职称
		$position	=	$this->position_ini;
		// 学历
		$education  =   $this->education_ini;
		// 职工类型
		$nature     =   $this->staff_nature_ini;
		// 党员显示
		$party      =	$this->party_ini;

		if ($_POST){

			$staff_name      = $this->post->staff_name;
			$staff_number    = $this->post->staff_number;
			$staff_sex       = $this->post->staff_sex;
			$staff_position  = $this->post->staff_position;
			$staff_education = $this->post->staff_education;
			$staff_birth     = $this->post->staff_birth;
			$staff_card      = $this->post->staff_card;
			$staff_entry     = $this->post->staff_entry;
			$staff_img       = $this->post->staff_img;
			$staff_file      = $this->post->staff_file;
			$start_time      = $this->post->start_time;
			$end_time        = $this->post->end_time;
			$staff_tel       = $this->post->staff_tel;
			$staff_nature    = $this->post->staff_nature;
			$staff_party     = $this->post->staff_party;

			// 写入数据库
			$info = array(

			"staff_name"       => $staff_name,
			"staff_number"     => $staff_number,
			"staff_sex"        => $staff_sex,
			"staff_position"   => $staff_position,
			"staff_party"      => $staff_party,
			"staff_education"  => $staff_education,
			"staff_birth"      => $staff_birth,
			"staff_card"       => $staff_card,
			"staff_entry"      => $staff_entry,
			"staff_img"        => $staff_img,
			"staff_file"       => $staff_file,
			"start_time"       => $start_time,
			"end_time"         => $end_time,
			"staff_tel"        => $staff_tel,
			"staff_nature"     => $staff_nature,
			"status"           => 1,
			"update_time"      => date("Y-m-d H:i:s"),

			);
			$this->db->do_update("tbl_staff", $info, "staff_id='{$staff_id}'");

			// 跳转
			Helper_Client::location("修改成功", "index.php?a=teacher.list");
		}

		$this->tpl->assign("position", $position);
		$this->tpl->assign("education", $education);
		$this->tpl->assign("nature", $nature);
		$this->tpl->assign("party", $party);

		$this->tpl->assign("staff_data", $staff_data);
		$this->tpl->display("teacher/teacher.update.tpl.php");
	}

	/** 教师档案删除 **/
	public function actionDel ()
	{
		$staff_id = (int)$this->get->staff_id;
		$this->db->query("DELETE  FROM `tbl_staff` WHERE staff_id='{$staff_id}'");
		// 删除user表
		$this->model->user->getdel($staff_id,'staff');
		Helper_Client::location("删除成功", "index.php?a=teacher.list");
	}

	//------------------------------------------------------------------------------//

	/** 教师信息列表 **/
	public function actionTeacherList ()
	{

		$staff_name			= $this->post->staff_name;
		$student_name		= $this->post->student_name;
		$student_number		= $this->post->student_number;

		// 查询条件
		$where = "WHERE 1=1 ";

		if(!empty($staff_name)){
			$where .= " AND staff_name LIKE '%{$staff_name}%' ";
			$this->tpl->assign("grade_id", $grade_id);
		}
		/*// 点头排序
		$rank = " ";
		if($student_number == desc){
		$rank .= " student_number DESC ";
		}
		if($student_number == asc){
		$rank .= " student_number ASC ";
		}
		if($student_name == desc){
		$rank .= " student_name DESC ";
		}
		if($student_name == asc){
		$rank .= " student_name ASC ";
		}
		*/
		// 分页
		YOU::loadLib('page', "", '0');
		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff`");
		$count = $tmp['count'];
		$page_total = ceil($count/PAGE_LIMIT);

		// 当前页
		$p = intval($_GET['p']);
		if ($p == 0){
			$p  = 1;
		}
		if ($p > 1){
			$start = PAGE_LIMIT * ($p-1);
		}else{
			$start = 0;
		}

		$staff_lists = $this->db->fetchAll("SELECT * FROM `tbl_staff` {$where} ORDER BY staff_id DESC LIMIT {$start}, ".PAGE_LIMIT."");
		$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
		$page->next_page   = '下一页>';
		$page->pre_page    = '<上一页';
		$page->style_path  = "static/page_style";
		$this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("staff_lists", $staff_lists);
		$this->tpl->assign("staffname_lists", $staffname_lists);
		$this->tpl->display("teacher/teacherinfo.list.tpl.php");
	}

	/** 教师信息添加 **/
	public function actionTeacherAdd()
	{
		if ($_POST){
			$staff_number		= $this->post->staff_number;
			$staff_name			= $this->post->staff_name;
			$staff_sex			= $this->post->staff_sex;
			$staff_birth		= $this->post->staff_birth;
			$staff_education	= $this->post->staff_education;
			$staff_position		= $this->post->staff_position;
			$start_time			= $this->post->start_time;
			$end_time			= $this->post->end_time;

			// 写入数据库
			$info = array(
			"staff_number"		=> $staff_number,
			"staff_name"		=> $staff_name,
			"staff_sex"			=> $staff_sex,
			"staff_birth"		=> $staff_birth,
			"staff_education"	=> $staff_education,
			"staff_position"	=> $staff_position,
			"start_time"		=> $start_time,
			"end_time"			=> $end_time,
			"status"            => 1,
			"create_time"       => date("Y-m-d H:i:s"),
			"update_time"       => "0000-00-00 00:00:00",
			);
			$this->db->do_insert("tbl_staff", $info);
			// 跳转
			Helper_Client::location("添加成功", "index.php?a=teacher.list");
		}
		$this->tpl->display("teacher/teacherinfo.add.tpl.php");
	}

	/** 教师信息修改 **/
	public function actionTeacherUpdate()
	{
		$staff_id   = (int)$this->get->staff_id;
		$staff_data = $this->db->fetchRow("SELECT * FROM `tbl_staff` WHERE staff_id='{$staff_id}'");
		if (empty($staff_data)){
			Helper_Client::alert("人员不存在");
		}
		if ($_POST){
			$staff_number		= $this->post->staff_number;
			$staff_name			= $this->post->staff_name;
			$staff_sex			= $this->post->staff_sex;
			$staff_birth		= $this->post->staff_birth;
			$staff_education	= $this->post->staff_education;
			$staff_position		= $this->post->staff_position;
			$start_time			= $this->post->start_time;
			$end_time			= $this->post->end_time;

			// 写入数据库
			$info = array(
			"staff_number"     => $staff_number,
			"staff_name"       => $staff_name,
			"staff_sex"        => $staff_sex,
			"staff_birth"      => $staff_birth,
			"staff_education"  => $staff_education,
			"staff_position"   => $staff_position,
			"start_time"	   => $start_time,
			"end_time"         => $end_time,
			"status"           => 1,
			"update_time"      => date("Y-m-d H:i:s"),
			);

			$this->db->do_update("tbl_staff", $info, "staff_id='{$staff_id}'");
			// 跳转
			Helper_Client::location("修改成功", "index.php?a=teacher.teacherlist");
		}
		$this->tpl->assign("staff_data", $staff_data);
		$this->tpl->display("teacher/teacherinfo.update.tpl.php");
	}

	/** 教师信息删除 **/
	public function actionTeacherDel ()
	{
		$staff_id = (int)$this->get->staff_id;
		$this->db->query("DELETE  FROM `tbl_staff` WHERE staff_id='{$staff_id}'");
		Helper_Client::location("删除成功", "index.php?a=teacher.teacherlist");
	}

	//---------------------------------------------------------------------------------------------------------------------------------------

	/** 教师统计汇总列表 **/
	public function actionTeacherCountList()
	{
		//按姓名查询
		$staff_name   = (int)$this->get->staff_name;
		$staff_lists = $this->db->fetchAll("SELECT * FROM `tbl_staff` WHERE staff_name='{$staff_name}'");
		//取教师的总人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff`");
		$staff['staff_count']    = $row['count'];
		//取性别为男的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_sex`='1'");
		$staff['man_count']      = $row['count'];
		//取性别为女的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_sex`='0'");
		$staff['woman_count']    = $row['count'];

		//取学历为专科以下的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_education`='1'");
		$staff['specialtyunder_count']  = $row['count'];
		//取学历为专科的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_education`='2'");
		$staff['specialty_count']       = $row['count'];
		//取学历为本科的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_education`='3'");
		$staff['undergraduate_count']   = $row['count'];
		//取学历为研究生的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_education`='4'");
		$staff['graduate_count']        = $row['count'];
		//取学历为研究生以上的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_education`='5'");
		$staff['graduateabove_count']   = $row['count'];
		//取职称为高级的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_position`='5'");
		$staff['senior_count']          = $row['count'];
		//取职称为正高级的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_position`='6'");
		$staff['seniorh_count']          = $row['count'];
		//取职称为一级的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_position`='2'");
		$staff['onelevel_count']        = $row['count'];
		//取职称为二级的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_position`='3'");
		$staff['twolevel_count']        = $row['count'];
		//取职称为三级的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_position`='4'");
		$staff['threelevel_count']        = $row['count'];
		//取职称为未定级的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_position`='1'");
		$staff['notgrade_count']        = $row['count'];
		//取为党员的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_party`='1'");
		$staff['party_count']           = $row['count'];
		//取为预备党员的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_party`='2'");
		$staff['prepparty_count']       = $row['count'];
		//取为非党员的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_party`='0'");
		$staff['noparty_count']         = $row['count'];
		//取为外聘的人数
		$naturerow = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_external`='1'");
		$staff['nature_count']          = $naturerow['count'];
		//取为退休的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_sign`='1'");
		$staff['retire_count']          = $row['count'];

		$this->tpl->assign("staff", $staff);
		$this->tpl->assign("staff_lists", $staff_lists);
		$this->tpl->display("teacher/teachercount.list.tpl.php");
	}
	//---------------------------------------------------------------------------------------------------------------------------------------
	public function actionoutda(){

		$staff_name   = (int)$this->get->staff_name;
		$staff_lists = $this->db->fetchAll("SELECT * FROM `tbl_staff` WHERE staff_name='{$staff_name}'");
		$info = array();
		//取教师的总人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff`");
		$staff['staff_count']    = $row['count'];
		$info[] = $row['count'];

		//取性别为男的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_sex`='1'");
		$staff['man_count']      = $row['count'];
		$info[] = $row['count'];
		//取性别为女的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_sex`='0'");
		$staff['woman_count']    = $row['count'];
		$info[] = $row['count'];

		//取学历为研究生以上的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_education`='5'");
		$staff['graduateabove_count']   = $row['count'];
		$info[] = $row['count'];
		//取学历为研究生的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_education`='4'");
		$staff['graduate_count']        = $row['count'];
		$info[] = $row['count'];
		//取学历为本科的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_education`='3'");
		$staff['undergraduate_count']   = $row['count'];
		$info[] = $row['count'];


		//取学历为专科的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_education`='2'");
		$staff['specialty_count']       = $row['count'];
		$info[] = $row['count'];


		//取学历为专科以下的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_education`='1'");
		$staff['specialtyunder_count']  = $row['count'];
		$info[] = $row['count'];




		//取职称为高级的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_position`='5'");
		$staff['senior_count']          = $row['count'];
		$info[] = $row['count'];

		//取职称为正高级的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_position`='6'");
		$staff['seniorh_count']          = $row['count'];
		$info[] = $row['count'];

		//取职称为一级的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_position`='2'");
		$staff['onelevel_count']        = $row['count'];
		$info[] = $row['count'];

		//取职称为二级的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_position`='3'");
		$staff['twolevel_count']        = $row['count'];
		$info[] = $row['count'];

		//取职称为三级的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_position`='4'");
		$staff['threelevel_count']        = $row['count'];
		$info[] = $row['count'];

		//取职称为未定级的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_position`='1'");
		$staff['notgrade_count']        = $row['count'];
		$info[] = $row['count'];

		//取为党员的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_party`='1'");
		$staff['party_count']           = $row['count'];
		$info[] = $row['count'];

		//取为预备党员的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_party`='2'");
		$staff['prepparty_count']       = $row['count'];
		$info[] = $row['count'];

		//取为非党员的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_party`='0'");
		$staff['noparty_count']         = $row['count'];
		$info[] = $row['count'];

		//取为外聘的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_external`='1'");
		$staff['nature_count']          = $row['count'];
		$info[] = $row['count'];
		//echo $row['count'];exit;

		//取为退休的人数
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` WHERE `staff_sign`='1'");
		$staff['retire_count']          = $row['count'];
		$info[] = $row['count'];

		$data_lists[]= $info;
		//var_dump($data_lists);exit;
		$this->model->excel->outData("tteacher", $data_lists);
	}

	/** 统计查询条件页 **/
	public function actionSelectList()
	{

        if ($_POST){

            if($this->post->posttype==1){
                $condition = $this->post->condition;//条件
                $content   = $this->post->content;//内容
                $this->tpl->assign("condition",$condition);
                $this->tpl->assign("content",$content);
                $_SESSION['content'] = $content;//为了回显此session并没有释放
                $_SESSION['condition'] = $condition;
            }else{
                $where = ' 1=1 ';
                foreach ($_POST as $key => $value){
                    switch ($key){
                        case 'staff_birth_from':
                            if(!empty($value))$where .= " and `staff_birth` >= '{$value}' ";
                            break;
                        case 'staff_birth_to':
                            if(!empty($value))$where .= " and `staff_birth` <= '{$value}' ";
                            break;
                        case 'start_time_from':
                            if(!empty($value))$where .= " and `start_time` >= '{$value}' ";
                            break;
                        case 'start_time_to':
                            if(!empty($value))$where .= " and `start_time` <= '{$value}' ";
                            break;
                        case 'end_time_from':
                            if(!empty($value))$where .= " and `end_time` >= '{$value}' ";
                            break;
                        case 'end_time_to':
                            if(!empty($value))$where .= " and `end_time` <= '{$value}' ";
                            break;
                        case 'staff_basic_start_from':
                            if(!empty($value))$where .= " and `staff_basic_start` >= '{$value}' ";
                            break;
                        case 'staff_basic_start_to':
                            if(!empty($value))$where .= " and `staff_basic_start` <= '{$value}' ";
                            break;
                        case 'staff_basic_end_from':
                            if(!empty($value))$where .= " and `staff_basic_end` >= '{$value}' ";
                            break;
                        case 'staff_basic_end_to':
                            if(!empty($value))$where .= " and `staff_basic_end` <= '{$value}' ";
                            break;
                        case 'staff_ctime_from':
                            if(!empty($value))$where .= " and `staff_ctime` >= '{$value}' ";
                            break;
                        case 'staff_ctime_to':
                            if(!empty($value))$where .= " and `staff_ctime` <= '{$value}' ";
                            break;
                        case 'staff_party_date_from':
                            if(!empty($value))$where .= " and `staff_party_date` >= '{$value}' ";
                            break;
                        case 'staff_party_date_to':
                            if(!empty($value))$where .= " and `staff_party_date` <= '{$value}' ";
                            break;
                        case 'staff_graduate_time_from':
                            if(!empty($value))$where .= " and `staff_graduate_time` >= '{$value}' ";
                            break;
                        case 'staff_graduate_time_to':
                            if(!empty($value))$where .= " and `staff_graduate_time` <= '{$value}' ";
                            break;
                        default:
                            if($value==0||!empty($value))$where .= " and `{$key}` = '{$value}' ";
                    }

                }
                $things = implode(',',array_flip($_SESSION['content']));
                $teacher_lists = $this->db->fetchAll("select {$things} from `tbl_staff` WHERE {$where}");

//               处理下数据
                foreach ($teacher_lists as $key =>$value){

                    if(isset($value['staff_sex'])){$teacher_lists[$key]['staff_sex'] = $this->sex_ini[$value['staff_sex']];}

                    if(isset($value['staff_education']))$teacher_lists[$key]['staff_education'] = $this->education_ini[$value['staff_education']];

                    if(isset($value['staff_position']))$teacher_lists[$key]['staff_position'] = $this->position_ini[$value['staff_position']];//职称

                    if(isset($value['staff_sign']))$teacher_lists[$key]['staff_sign'] = $this->sign_ini[$value['staff_sign']];

                    if(isset($value['staff_party']))$teacher_lists[$key]['staff_party'] = $this->party_ini[$value['staff_party']];

                    if(isset($value['staff_assess']))$teacher_lists[$key]['staff_assess'] = $this->assess_ini[$value['staff_assess']];

                        //                    case  'staff_nature':
                        //                        $info[$i] = $this->staff_nature_ini[$value[$v['name']]];
                        //                        break;

                }
                $this->tpl->assign('teacher_lists',$teacher_lists);
                $_SESSION['ttchers'] = $teacher_lists;
                $this->tpl->assign('content',$_SESSION['content']);
                $this->tpl->assign('condition',$_SESSION['condition']);//unset($_SESSION['condition']);
                //unset($_SESSION['content']);
            }

        }

        //教师查找条件以及显示内容
        $record_ini = $this->model->record->getCheck("teacher_list", $this->teacher_record_ini);

        $this->tpl->assign("record_ini", $record_ini);
        $this->tpl->display("teacher/teacherselect.list.tpl.php");
	}

//统计导出session版本
    public function actionTtcherout(){
        if($_SESSION['content']&&$_SESSION['ttchers']){
            $this->model->excel->excel_ini['ttcher']['col'] = array_values($_SESSION['content']);
            $this->model->excel->outData("ttcher", $_SESSION['ttchers']);
        }else{
            Helper_Client::alert("会话过期，请重新查询");
        }
    }
	/** 统计查询结果列表 **/
	public function actionCountSelectList ()
	{
		$report_lists = $this->db->fetchAll("SELECT * FROM `tbl_report`");
		$this->tpl->assign("report_lists", $report_lists);
		$this->tpl->display("teacher/teachercountselect.list.tpl.php");
	}

	//---------------------------------------------------------------------------------------------------------------------------------------

	/** 教师历年教学信息列表 **/
	public function actionTeachList()
	{

		//顶部学期查询
        $staff_id = $this->get->staff_id;
		$semester_id = (int)$this->get->semester_id;
		$this->tpl->assign("semester_id",$semester_id);
		$semester_lists = $this->db->fetchAll("SELECT `semester_id`,`semester_name` FROM `tbl_semester`");
		//获取到学年学期
		$semester_data = $this->db->fetchRow("SELECT `semester_name`,`semester_xname` FROM `tbl_semester` WHERE `semester_id`='{$semester_id}'");
		// 分页
		YOU::loadLib('page', "", '0');
		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff`");
		$count = $tmp['count'];
		$page_total = ceil($count/5);

		// 当前页
		$p = intval($_GET['p']);
		if ($p == 0){
			$p  = 1;
		}
		if ($p > 1){
			$start = 5 * ($p-1);
		}else{
			$start = 0;
		}
		$staff_lists = $this->db->fetchAll("SELECT `staff_id` FROM `tbl_staff` LIMIT {$start}," ."5");
		$alldatas = array();
		foreach ( $staff_lists as $key => $value ) {
			$staff_id    = (int)$value['staff_id'];
			if(is_null($staff_id)){continue;}

			$department_id = $this->model->staff->getInfo($staff_id, 'department_id') ;
			if (!empty($department_id)) {
				$department_id = 0;
			}
			$position_id = $this->model->staff->getInfo($staff_id, 'staff_position') ;
			if (!empty($position_id)) {
				$position_id = 0;
			}
			$where = '';
			//获取到任职情况
			$row = $this->db->fetchRow("SELECT `department_name` FROM `tbl_department` WHERE `department_id` = {$department_id}");
			$staff['department_data'] = $row['department_name'];
			//var_dump($staff['department_data']);
			$row = $this->db->fetchRow("SELECT `position_name` FROM `tbl_position` WHERE `position_id`='{$position_id}'");
			$staff['position_data'] = $row['position_name'];
			//获取到任课信息

			$staff['subject_data'] = $this->db->fetchAll("SELECT a.*,b.class_name,c.subject_name FROM `tbl_staff_subject` as a,`tbl_class` as b,`tbl_subject` as c WHERE a.subject_id = c.subject_id AND a.class_id = b.class_id AND a.staff_id='{$staff_id}' AND a.semester_id='{$semester_id}'");
			//var_dump($staff['subject_data']);exit;

			//        $grade_data = $this->db->fetchRow("SELECT `grade_name` FROM `tbl_grade` WHERE `staff_id`='{$staff_id}' AND `semester_id`='{$semester_id}'");
			//		$staff['grade_data']        = $row['grade_name'];
			//subject里的class_id
			$class_data = $this->db->fetchRow("SELECT `class_name` FROM `tbl_class` WHERE `staff_id`='{$staff_id}' AND `semester_id`='{$semester_id}'");
			$staff['class_data'] = $row['class_name'];

			//获取到周课时 subject hour_count
			$staff['hour_data'] = $this->db->fetchRow("SELECT sum(`week_hour`) FROM `tbl_staff_subject` WHERE `staff_id`='{$staff_id}' AND `semester_id`='{$semester_id}'");
			//var_dump($staff['hour_data']);
			//获取到个人获奖信息//where   日期在学期中
			$row = $this->db->fetchAll("SELECT `achieve_name` FROM `tbl_achieve` WHERE `achieve_owner`={$staff_id}");

			foreach ($row as $k => $v){
				$achieves[] = $v['achieve_name'];
			}
			$staff['award_data'] = $achieves;
			// var_dump($achieves);exit;

			//年度考核
			$assess_data = $this->db->fetchRow("SELECT `staff_assess` FROM `tbl_staff` WHERE `staff_id`='{$staff_id}' ");
			$staff['assess_data'] = $row['assess_name'];
			//教学成绩
			//$score_data = $this->db->fetchRow("SELECT `score_score`,`score_rank` FROM `tbl_score` WHERE `staff_id`='{$staff_id}' AND `semester_id`='{$semester_id}'");
			$staff['score_data'] = $row['score_name'];
			$alldatas[] = $staff;
		}

		$page = new Page(array('total' => $count, 'perpage' => 5));
		$page->next_page   = '下一页>';
		$page->pre_page    = '<上一页';
		$page->style_path  = "static/page_style";
		$this->tpl->assign("page", $page->show(4, "yahoo"));

		$this->tpl->assign("semester_lists", $semester_lists);
		$this->tpl->assign("semester_data", $semester_data);
		$this->tpl->assign("alldatas", $alldatas);
		$this->tpl->display("teacher/teacherteach.list.tpl.php");
	}
	/** -------------------------------------------通讯录------------------------------------- **/

	/** 通讯录 **/
	public function actionContactList ()
	{
		//按条件搜索
		$where = " WHERE 1=1 ";

		//获取到页面传过来的要搜索的条件
		$staff_name    = $this->get->staff_name;
		if (!empty($staff_name)) {
			$where .= " AND staff_name LIKE '%{$staff_name}%' ";
			$this->tpl->assign("staff_name", $staff_name);
		}
		$staff_mobile    = $this->get->staff_mobile;
		if (!empty($staff_mobile)) {
			$where .= " AND staff_mobile LIKE '%{$staff_mobile}%' ";
			$this->tpl->assign("staff_mobile", $staff_mobile);
		}
		$staff_tel    = $this->get->staff_tel;
		if (!empty($staff_tel)) {
			$where .= " AND staff_tel LIKE '%{$staff_tel}%' ";
			$this->tpl->assign("staff_tel", $staff_tel);
		}


		// 分页
		YOU::loadLib('page', "", '0');
		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff` {$where} ");
		$count = $tmp['count'];
		$page_total = ceil($count/PAGE_LIMIT);

		// 当前页
		$p = intval($_GET['p']);
		if ($p == 0){
			$p  = 1;
		}
		if ($p > 1){
			$start = PAGE_LIMIT * ($p-1);
		}else{
			$start = 0;
		}


		$staff_lists = $this->db->fetchAll("SELECT * FROM `tbl_staff` {$where} ORDER BY staff_id ASC LIMIT {$start}, ".PAGE_LIMIT);
		$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
		$page->next_page   = '下一页>';
		$page->pre_page    = '<上一页';
		$page->style_path  = "static/page_style";

		$this->tpl->assign("page", $page->show(4, "yahoo"));

		$this->tpl->assign("staff_lists", $staff_lists);
		$this->tpl->display("teacher/teacher.contactlist.tpl.php");
	}
	// 下载
	public function actionoutput(){
		$fname = 'teacher_in.xls';
		$fpath = TP_PATH."/{$fname}";
		//echo '3333333333333333333333333333333333333'.$fpath;exit;
		//echo $fpath ; exit;
		// 输出下载文件头s
		header("Content-Disposition: attachment; filename={$fname}");
		// 在线输出

		readfile($fpath);
		//$objWriter->save('php://output');
	}

}

?>